//
//  IsFirstUseAppViewController.m
//  1gene
//
//  Created by 1jiyin on 16/5/23.
//  Copyright © 2016年 1jiyin. All rights reserved.
//

#import "IsFirstUseAppViewController.h"
#import "AppDelegate.h"

@interface IsFirstUseAppViewController ()

@end

@implementation IsFirstUseAppViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor whiteColor];
    [self createUI];
    // Do any additional setup after loading the view.
}
-(void)createUI
{
    [self firstUseApp];
    
    
    //存储当前时间
    NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
    NSString *lastSignTime=[formatter stringFromDate:[NSDate date]];
    NSLog(@"第一次进入app的时间===%@",lastSignTime);
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
    [user setObject:lastSignTime forKey:@"lastSignTime"];
    [user synchronize];
}


//第一次使用app
-(void)firstUseApp
{
    NSArray *imgArr=@[@"start1",@"start2",@"start3",@"start4"];
    
    UIScrollView *scroll=[[UIScrollView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    scroll.showsHorizontalScrollIndicator=NO;
    scroll.bounces=NO;
    scroll.pagingEnabled=YES;
    scroll.contentSize=CGSizeMake(scroll.frame.size.width*4, scroll.frame.size.height);
    [self.view addSubview:scroll];
    for (int i=0; i<imgArr.count; i++) {
        UIImageView *imgView=[[UIImageView alloc]initWithFrame:CGRectMake(scroll.frame.size.width*i, 0, scroll.frame.size.width, scroll.frame.size.height)];
        imgView.image=[UIImage imageNamed:imgArr[i]];
        [scroll addSubview:imgView];
        if (i==3) {
            imgView.userInteractionEnabled=YES;
            UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(appStart:)];
            [imgView addGestureRecognizer:tap];
        }
        
    }
    
}
-(void)appStart:(UITapGestureRecognizer *)tap
{
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
    [user setBool:YES forKey:@"firstUseApp"];
    [user synchronize];
    
    AppDelegate *app=[UIApplication sharedApplication].delegate;
    [app showMainViewController:0];
    
    //[self showMainViewController:0];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
